#include "instructions/references/arraylength.h"
#include "rtda/heap/object.h"

namespace jvm {
    namespace instructions {

        void ARRAY_LENGTH::execute(std::shared_ptr<rtda::Frame> pframe) {
            auto&& stack = pframe->getOperandStack();
            auto&& arrRef = stack->popRef();
            if (arrRef == nullptr) {
                throw std::runtime_error("java.lang.NullPointerException");
            }

            int32_t arrLen = arrRef->arrayLength();
            stack->pushInt(arrLen);
        }

    } // namespace instructions
}// namespace jvm